import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

// import { h } from 'vue';
import { DictEnum } from '@vben/constants';
// import { VbenIcon } from '@vben/icons';
import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
// import { z } from '#/adapter/form';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '任务名称',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.CONTACT_TASK_TYPE, true),
    },
    fieldName: 'type',
    label: '任务类型',
  },
  {
    component: 'ExhibitionSelect',
    fieldName: 'exhibitionId',
    label: '所属展会',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
    fieldName: 'number',
    label: '届数',
  },
  {
    component: 'RangePicker',
    fieldName: 'taskTime',
    label: '任务时间',
  },
  {
    component: 'UserListSelect',
    fieldName: 'createBy',
    label: '创建人',
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '任务名称',
    field: 'name',
    minWidth: 150,
  },
  {
    title: '任务类型',
    field: 'type',
    width: 120,
    slots: {
      default: ({ row }) => {
        return renderDict(row.type, DictEnum.CONTACT_TASK_TYPE, true);
      },
    },
    visible: false,
  },
  {
    title: '人员数量',
    field: 'employeeNum',
    width: 120,
    slots: { default: 'employeeNum' },
  },
  {
    title: '任务时间',
    field: 'startDate',
    width: 240,
    slots: {
      default: ({ row }) => {
        return (
          <div>
            <span>{row.startDate} - </span>
            {row.endDate ? <span>{row.endDate}</span> : ''}
          </div>
        );
      },
    },
  },
  {
    title: '完成率',
    field: 'completionRate',
    width: 130,
    slots: { default: 'completionRate' },
    showOverflow: false,
  },
  {
    title: '备注',
    field: 'remark',
    showOverflow: true,
    visible: false,
  },
  {
    title: '创建人',
    field: 'createByName',
    width: 140,
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 180,
    visible: false,
  },
  {
    title: '最后更新人',
    field: 'updateByName',
    width: 140,
    visible: false,
  },
  {
    title: '最后更新时间',
    field: 'updateTime',
    width: 180,
    visible: false,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '任务ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.CONTACT_TASK_TYPE, true),
      optionType: 'button',
    },
    fieldName: 'type',
    rules: 'selectRequired',
    label: '任务类型',
  },
  {
    label: '任务名称',
    fieldName: 'name',
    component: 'Input',
    rules: 'required',
  },
  {
    component: 'ExhibitionSelect',
    fieldName: 'exhibitionId',
    label: '所属展会',
    rules: 'selectRequired',
  },
  {
    label: '届数',
    fieldName: 'number',
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
    rules: 'selectRequired',
  },
  {
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    fieldName: 'startDate',
    label: '开始时间',
    rules: 'selectRequired',
  },
  {
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      showTime: false,
      valueFormat: 'YYYY-MM-DD',
    },
    fieldName: 'endDate',
    label: '结束时间',
    rules: 'selectRequired',
  },
  {
    component: 'SmsTemplateSelect',
    fieldName: 'smsTemplateIds',
    label: '短信模板',
    componentProps: {
      multiple: true,
    },
    defaultValue: [],
    rules: 'selectRequired',
  },
  {
    component: 'EmailTemplateSelect',
    fieldName: 'emailTemplateIds',
    label: '邮件模板',
    componentProps: {
      multiple: true,
    },
    defaultValue: [],
    rules: 'selectRequired',
  },
  {
    component: 'UserListSelect',
    fieldName: 'userIds',
    componentProps: {
      mode: 'multiple',
    },
    defaultValue: [],
    label: '呼叫人员',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
  },
];

export const detailsSchema: DetailsModalSchemaGetter = () => [
  {
    label: '任务名称',
    fieldName: 'name',
    copy: true,
  },
  {
    label: '任务类型',
    fieldName: 'type',
    dictEnum: DictEnum.CONTACT_TASK_TYPE,
    dictEnumFormatNumber: true,
  },
  {
    label: '所属展会',
    fieldName: 'exhibitionName',
  },
  {
    label: '届数',
    fieldName: 'number',
    dictEnum: DictEnum.EXHIBITION_NUMBER,
  },
  {
    label: '人员数量',
    fieldName: 'employeeNum',
  },
  {
    label: '完成率',
    fieldName: 'completionRate',
    custom: true,
  },
  {
    label: '开始时间',
    fieldName: 'startDate',
  },
  {
    label: '结束时间',
    fieldName: 'endDate',
  },
  {
    label: '短信模板',
    fieldName: 'smsTemplates',
    custom: true,
  },
  {
    label: '邮件模板',
    fieldName: 'emailTemplates',
    custom: true,
  },
  {
    label: '备注',
    fieldName: 'remark',
    textWrap: true,
  },
];

export const taskDataColumns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '姓名',
    field: 'name',
    width: 150,
  },
  {
    title: '企业名称',
    field: 'companyName',
    minWidth: 160,
  },
  {
    title: '部门',
    field: 'departmentId',
    width: 160,
    slots: {
      default: ({ row }) => {
        return renderDict(row.departmentId, DictEnum.AUDIENCE_DEPARTMENT);
      },
    },
  },
  {
    title: '职位',
    field: 'positionId',
    width: 140,
    slots: {
      default: ({ row }) => {
        return renderDict(row.positionId, DictEnum.AUDIENCE_POSITION);
      },
    },
  },
  {
    title: '手机',
    field: 'mobile',
    width: 160,
  },
  {
    title: '所在地区',
    field: 'provinceName',
    width: 220,
    slots: {
      default: ({ row }) => {
        if (row?.cityName) {
          return (
            <span>
              {row.provinceName}
              {row.cityName}
            </span>
          );
        }

        return <span>{row?.provinceName}</span>;
      },
    },
  },
  {
    title: '呼叫状态',
    field: 'callStatus',
    width: 140,
    slots: {
      default: ({ row }) => {
        return renderDict(
          row.callStatus,
          DictEnum.CALL_TASK_AUDIENCE_STATUS,
          true,
        );
      },
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
];

export const importDataSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'taskId',
    label: '任务ID',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'PersonalFavoriteSelect',
    fieldName: 'favoriteId',
    label: '人员收藏夹',
    rules: 'selectRequired',
  },
];
